<?php
/**
 * BaseController
 *
 * PHP Version 5.4
 *
 * @author liuxuTJ <liuxuphp@icesmart.cn>
 */
namespace Admin\Controller;

use Think\Controller;
use Think\Page;

/**
 * Class BaseController
 */
class BaseController extends Controller
{

    /**
     * BaseController constructor.
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 获取分页
     *
     * @todo: 从小数到京学再到京师，现成的分页一概不用，搞到现在满世界的飞数据库语句
     */
    public function page($model, $where, $pagesize = 10)
    {
        //@todo: 没事少clone，容易玩爆数据库
        $modelClone = clone $model;
        $count = $model->where($where)->count();
        $model = $modelClone;
        $page = new Page($count, $pagesize);

        $page->parameter = I('get.');

        $model->limit($page->firstRow . ',' . $page->listRows);

        return $page;
    }
}